/**
 * Device detection utilities
 */

/**
 * Check if the current device is a mobile device
 * Uses a combination of screen width and user agent detection for accuracy
 */
export const isMobileDevice = () => {
    // Check screen width (most reliable for responsive design)
    const isMobileWidth = window.innerWidth <= 768;

    // Additional check using user agent (as a secondary verification)
    const userAgent = navigator.userAgent || navigator.vendor || window.opera;
    const mobileRegex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
    const isMobileAgent = mobileRegex.test(userAgent);

    // For iPads and tablets, we want to exclude them from "mobile" category
    const isTablet = /iPad|tablet|Tablet/i.test(userAgent) ||
        (isMobileAgent && Math.min(window.innerWidth, window.innerHeight) > 768);

    // Consider it mobile only if it has mobile width AND is not a tablet
    return isMobileWidth && !isTablet;
};

/**
 * Check if the current device is a tablet
 */
export const isTabletDevice = () => {
    const userAgent = navigator.userAgent || navigator.vendor || window.opera;
    const isTabletByAgent = /iPad|tablet|Tablet/i.test(userAgent);

    // Consider tablets based on screen size as well
    const isTabletBySize = window.innerWidth <= 1024 && window.innerWidth > 768;

    return isTabletByAgent || isTabletBySize;
};

/**
 * Check if the current device is a desktop
 */
export const isDesktopDevice = () => {
    return !isMobileDevice() && !isTabletDevice();
};
